import { WITHDRAWAL_TYPE__KEY, WITHDRAWAL_ICON, WITHDRAWAL_VALUE, WITHDRAWAL_TYPE } from '@/enum/withdrawal';
import { PAY_WAY_TYPE, PAY_WAY_ICON, PAY_WAT_NAME, PAY_STATUS, PAY_STATUS_NAME, PAY_STATUS_COLOR, PAY_STATUS_BGCOLOR } from '@/enum/pay';
import { DELIVER_TYPE, DELIVER_NAME, DELIVER_STATUS, DELIVER_STATUS_NAME, DELIVER_STATUS_COLOR, DELIVER_STATUS_BGCOLOR } from '@/enum/deliver';
import { TOPUP_CHECK_STATUS, TOPUP_CHECK_STATUS_LABEL, TOPUP_CHECK_STATUS_CLASSNAME } from '@/enum/topup';
import { ACTIVATE_STATUS, ACTIVATE_STATUS_COLOR, ACTIVATE_STATUS_BGCOLOR, ACTIVATE_STATUS_NAME } from '@/enum/device';
import { USER_LEVEL_TYPE, USER_LEVEL_TYPE_NAME, USER_LEVEL_TYPE_CARDIMAGE } from '@/enum/level';
import { AGREEMENT_TYPE, AGREEMENT_NAME, AGREEMENT_URL } from '@/enum/agreement';
import { PRIZE_TYPE, PRIZE_IMAGE, PRIZE_BRIEF_NAME,PRIZE_COLOR,PRIZE_BGCOLOR } from '@/enum/prize'
import { useToken } from '@/hooks/useToken';

import store from '@/store';


interface IGlobal {
	withdrawal_type_list : IWithdrawalTypeList,
	payOptionList : IPayOptionList,
	deliverOptionList : IDeliverOptionList,
	payStatusList : IPayStatusList,
	deliverStatusList : IDeliverStatusList,
	topupCheckStatusList : ITopupCheckStatusList,
	deviceActivateStatusList : IDeviceActivateStatusList,
	userLevelTypeList : IUserLevelTypeList,
	agreementOptionsList : IAgreementOptionsList,
	prizeOptionsList : IPrizeOptionsList,
	followStatushandle : (code : number) => void,
	authorization : (path : string) => void,
	resetWebUrl : (path : string) => void,
	showModel : () => void,
}

interface IWithdrawalType {
	type : WITHDRAWAL_TYPE,
	value : WITHDRAWAL_VALUE,
	icon : WITHDRAWAL_ICON,
	key : WITHDRAWAL_TYPE__KEY,
};

interface IWithdrawalTypeList {
	[WITHDRAWAL_TYPE__KEY : string] : IWithdrawalType
};

interface IPayOptionList {
	[PAY_WAY_TYPE : number] : IPayOption
};

interface IPayOption {
	type : PAY_WAY_TYPE,
	icon : PAY_WAY_ICON,
	name : PAY_WAT_NAME,
};

interface IDeliverOptionList {
	[DELIVER_TYPE : number] : IDeliverOption
}

interface IDeliverOption {
	name : DELIVER_NAME,
	type : DELIVER_TYPE,
}

interface IPayStatusList {
	[PAY_STATUS : number] : IPayStatus,
}

interface IPayStatus {
	name : PAY_STATUS_NAME,
	type : PAY_STATUS,
	color : PAY_STATUS_COLOR,
	bgColor : PAY_STATUS_BGCOLOR,
}

interface IDeliverStatusList {
	[DELIVER_STATUS : number] : IDeliverStatus,
}

interface IDeliverStatus {
	name : DELIVER_STATUS_NAME,
	type : DELIVER_STATUS,
	color : DELIVER_STATUS_COLOR,
	bgColor : DELIVER_STATUS_BGCOLOR,
}



interface ITopupCheckStatusList {
	[TOPUP_CHECK_STATUS : number] : ITopupCheckStatus
}

interface ITopupCheckStatus {
	type : TOPUP_CHECK_STATUS,
	name : TOPUP_CHECK_STATUS_LABEL,
	color : TOPUP_CHECK_STATUS_CLASSNAME,
}


interface IDeviceActivateStatus {
	type : ACTIVATE_STATUS,
	name : ACTIVATE_STATUS_NAME,
	color : ACTIVATE_STATUS_COLOR,
	bgColor : ACTIVATE_STATUS_BGCOLOR
}

interface IDeviceActivateStatusList {
	[ACTIVATE_STATUS : number] : IDeviceActivateStatus
}

interface IUserLevelTypeList {
	[USER_LEVEL_TYPE : number] : IUserLevelType;
}

interface IUserLevelType {
	type : USER_LEVEL_TYPE;
	name : USER_LEVEL_TYPE_NAME;
	card : USER_LEVEL_TYPE_CARDIMAGE;
}


interface IAgreementOptionsList {
	[AGREEMENT_TYPE : number] : IAgreemenType;
}

interface IAgreemenType {
	type : AGREEMENT_TYPE;
	name : AGREEMENT_NAME;
	url : AGREEMENT_URL;
}

interface IPrizeOptionsList {
	[PRIZE_TYPE : number] : IPrizeType;
}

interface IPrizeType {
	type : PRIZE_TYPE,
	icon : PRIZE_IMAGE,
	brief : PRIZE_BRIEF_NAME,
	color:PRIZE_COLOR,
	bgcolor:PRIZE_BGCOLOR,
}


const global : IGlobal = {
	withdrawal_type_list: {
		[WITHDRAWAL_TYPE__KEY.BALANCE]: {
			type: WITHDRAWAL_TYPE.BALANCE,
			value: WITHDRAWAL_VALUE.BALANCE,
			icon: WITHDRAWAL_ICON.BALANCE,
			key: WITHDRAWAL_TYPE__KEY.BALANCE
		},
		[WITHDRAWAL_TYPE__KEY.WECHAT]: {
			type: WITHDRAWAL_TYPE.WECHAT,
			value: WITHDRAWAL_VALUE.WECHAT,
			icon: WITHDRAWAL_ICON.WECHAT,
			key: WITHDRAWAL_TYPE__KEY.WECHAT
		},
		[WITHDRAWAL_TYPE__KEY.BANK_CARD]: {
			type: WITHDRAWAL_TYPE.BANK_CARD,
			value: WITHDRAWAL_VALUE.BANK_CARD,
			icon: WITHDRAWAL_ICON.BANK_CARD,
			key: WITHDRAWAL_TYPE__KEY.BANK_CARD
		},
		[WITHDRAWAL_TYPE__KEY.ALIPAY]: {
			type: WITHDRAWAL_TYPE.ALIPAY,
			value: WITHDRAWAL_VALUE.ALIPAY,
			icon: WITHDRAWAL_ICON.ALIPAY,
			key: WITHDRAWAL_TYPE__KEY.ALIPAY
		},
	},
	payOptionList: {
		[PAY_WAY_TYPE.BALANCE]: {
			type: PAY_WAY_TYPE.BALANCE,
			icon: PAY_WAY_ICON.BALANCE,
			name: PAY_WAT_NAME.BALANCE,
		},
		[PAY_WAY_TYPE.WECHAT]: {
			type: PAY_WAY_TYPE.WECHAT,
			icon: PAY_WAY_ICON.WECHAT,
			name: PAY_WAT_NAME.WECHAT,
		},
		// [PAY_WAY_TYPE.ALIPAY]:{
		// 	type:PAY_WAY_TYPE.ALIPAY,
		// 	icon:PAY_WAY_ICON.ALIPAY,
		// 	name:PAY_WAT_NAME.ALIPAY,
		// }
	},
	deliverOptionList: {
		[DELIVER_TYPE.EXPRESS]: {
			type: DELIVER_TYPE.EXPRESS,
			name: DELIVER_NAME.EXPRESS
		},
		[DELIVER_TYPE.OFFLINE]: {
			type: DELIVER_TYPE.OFFLINE,
			name: DELIVER_NAME.OFFLINE
		},
	},
	payStatusList: {
		[PAY_STATUS.UNPAY]: {
			type: PAY_STATUS.UNPAY,
			name: PAY_STATUS_NAME.UNPAY,
			color: PAY_STATUS_COLOR.UNPAY,
			bgColor: PAY_STATUS_BGCOLOR.UNPAY,
		},
		[PAY_STATUS.PAID]: {
			type: PAY_STATUS.PAID,
			name: PAY_STATUS_NAME.PAID,
			color: PAY_STATUS_COLOR.PAID,
			bgColor: PAY_STATUS_BGCOLOR.PAID,
		},
		[PAY_STATUS.REFUNDING]: {
			type: PAY_STATUS.REFUNDING,
			name: PAY_STATUS_NAME.REFUNDING,
			color: PAY_STATUS_COLOR.REFUNDING,
			bgColor: PAY_STATUS_BGCOLOR.REFUNDING,
		},
		[PAY_STATUS.REFUNDED]: {
			type: PAY_STATUS.REFUNDED,
			name: PAY_STATUS_NAME.REFUNDED,
			color: PAY_STATUS_COLOR.REFUNDED,
			bgColor: PAY_STATUS_BGCOLOR.REFUNDED,
		},
		[PAY_STATUS.CANCEL]: {
			type: PAY_STATUS.CANCEL,
			name: PAY_STATUS_NAME.CANCEL,
			color: PAY_STATUS_COLOR.CANCEL,
			bgColor: PAY_STATUS_BGCOLOR.CANCEL,
		}
	},
	deliverStatusList: {
		[DELIVER_STATUS.UNDELIVERED]: {
			type: DELIVER_STATUS.UNDELIVERED,
			name: DELIVER_STATUS_NAME.UNDELIVERED,
			color: DELIVER_STATUS_COLOR.UNDELIVERED,
			bgColor: DELIVER_STATUS_BGCOLOR.UNDELIVERED,
		},
		[DELIVER_STATUS.DELIVERED]: {
			type: DELIVER_STATUS.DELIVERED,
			name: DELIVER_STATUS_NAME.DELIVERED,
			color: DELIVER_STATUS_COLOR.DELIVERED,
			bgColor: DELIVER_STATUS_BGCOLOR.DELIVERED,
		},
		[DELIVER_STATUS.ORDERENTRY]: {
			type: DELIVER_STATUS.ORDERENTRY,
			name: DELIVER_STATUS_NAME.ORDERENTRY,
			color: DELIVER_STATUS_COLOR.ORDERENTRY,
			bgColor: DELIVER_STATUS_BGCOLOR.ORDERENTRY,
		},
		[DELIVER_STATUS.RECEIVED]: {
			type: DELIVER_STATUS.RECEIVED,
			name: DELIVER_STATUS_NAME.RECEIVED,
			color: DELIVER_STATUS_COLOR.RECEIVED,
			bgColor: DELIVER_STATUS_BGCOLOR.RECEIVED,
		},
	},
	topupCheckStatusList: {
		[TOPUP_CHECK_STATUS.PENDING]: {
			type: TOPUP_CHECK_STATUS.PENDING,
			name: TOPUP_CHECK_STATUS_LABEL.PENDING,
			color: TOPUP_CHECK_STATUS_CLASSNAME.PENDING,
		},
		[TOPUP_CHECK_STATUS.FAIL]: {
			type: TOPUP_CHECK_STATUS.FAIL,
			name: TOPUP_CHECK_STATUS_LABEL.FAIL,
			color: TOPUP_CHECK_STATUS_CLASSNAME.FAIL,
		},
		[TOPUP_CHECK_STATUS.SUCCESS]: {
			type: TOPUP_CHECK_STATUS.SUCCESS,
			name: TOPUP_CHECK_STATUS_LABEL.SUCCESS,
			color: TOPUP_CHECK_STATUS_CLASSNAME.SUCCESS,
		}
	},
	deviceActivateStatusList: {
		[ACTIVATE_STATUS.ACTIVATED]: {
			type: ACTIVATE_STATUS.ACTIVATED,
			name: ACTIVATE_STATUS_NAME.ACTIVATED,
			color: ACTIVATE_STATUS_COLOR.ACTIVATED,
			bgColor: ACTIVATE_STATUS_BGCOLOR.ACTIVATED,
		},
		[ACTIVATE_STATUS.UNACTIVATED]: {
			type: ACTIVATE_STATUS.UNACTIVATED,
			name: ACTIVATE_STATUS_NAME.UNACTIVATED,
			color: ACTIVATE_STATUS_COLOR.UNACTIVATED,
			bgColor: ACTIVATE_STATUS_BGCOLOR.UNACTIVATED,
		},
		[ACTIVATE_STATUS.PSEUDO_ACTIVATED]: {
			type: ACTIVATE_STATUS.PSEUDO_ACTIVATED,
			name: ACTIVATE_STATUS_NAME.PSEUDO_ACTIVATED,
			color: ACTIVATE_STATUS_COLOR.PSEUDO_ACTIVATED,
			bgColor: ACTIVATE_STATUS_BGCOLOR.PSEUDO_ACTIVATED,
		}
	},
	userLevelTypeList: {
		[USER_LEVEL_TYPE.CHARMAN]: {
			type: USER_LEVEL_TYPE.CHARMAN,
			name: USER_LEVEL_TYPE_NAME.CHARMAN,
			card: USER_LEVEL_TYPE_CARDIMAGE.CHARMAN,
		},
		[USER_LEVEL_TYPE.DIRECTOR]: {
			type: USER_LEVEL_TYPE.DIRECTOR,
			name: USER_LEVEL_TYPE_NAME.DIRECTOR,
			card: USER_LEVEL_TYPE_CARDIMAGE.DIRECTOR,
		},
		[USER_LEVEL_TYPE.NORMAL]: {
			type: USER_LEVEL_TYPE.NORMAL,
			name: USER_LEVEL_TYPE_NAME.NORMAL,
			card: USER_LEVEL_TYPE_CARDIMAGE.NORMAL,
		},
		[USER_LEVEL_TYPE.PARTNER]: {
			type: USER_LEVEL_TYPE.PARTNER,
			name: USER_LEVEL_TYPE_NAME.PARTNER,
			card: USER_LEVEL_TYPE_CARDIMAGE.PARTNER,
		},
	},
	agreementOptionsList: {
		[AGREEMENT_TYPE.PRIVACY]: {
			type: AGREEMENT_TYPE.PRIVACY,
			name: AGREEMENT_NAME.PRIVACY,
			url: AGREEMENT_URL.PRIVACY,
		},
		[AGREEMENT_TYPE.SERVICE]: {
			type: AGREEMENT_TYPE.SERVICE,
			name: AGREEMENT_NAME.SERVICE,
			url: AGREEMENT_URL.SERVICE,
		}
	},
	prizeOptionsList: {
		[PRIZE_TYPE.AMOUNT]: {
			type: PRIZE_TYPE.AMOUNT,
			icon: PRIZE_IMAGE.AMOUNT,
			brief:PRIZE_BRIEF_NAME.AMOUNT,
			color:PRIZE_COLOR.AMOUNT,
			bgcolor:PRIZE_BGCOLOR.AMOUNT,
		},
		[PRIZE_TYPE.NONE]: {
			type: PRIZE_TYPE.NONE,
			icon: PRIZE_IMAGE.NONE,
			brief:PRIZE_BRIEF_NAME.NONE,
			color:PRIZE_COLOR.NONE,
			bgcolor:PRIZE_BGCOLOR.NONE,
		},
		[PRIZE_TYPE.PRIZE]: {
			type: PRIZE_TYPE.PRIZE,
			icon: PRIZE_IMAGE.PRIZE,
			brief:PRIZE_BRIEF_NAME.PRIZE,
			color:PRIZE_COLOR.PRIZE,
			bgcolor:PRIZE_BGCOLOR.PRIZE,
		},
		[PRIZE_TYPE.SCORE]: {
			type: PRIZE_TYPE.SCORE,
			icon: PRIZE_IMAGE.SCORE,
			brief:PRIZE_BRIEF_NAME.SCORE,
			color:PRIZE_COLOR.SCORE,
			bgcolor:PRIZE_BGCOLOR.SCORE,
		},
	},
	followStatushandle(code : number) {
		const { getTokenSync } = useToken();
		switch (code) {
			case -1001:
				uni.showModal({
					title: '未关注公众号',
					content: '当前账号未关注公众号,为保证交易信息正常送达，请使用其他方式登录后，关注小律优创公众号',
					confirmText: '确定',
					cancelText: '取消',
					success: (res) => {
						if (res.confirm) uni.router.route('/pages_login/login/login?type=vcode');
					}
				})
				break;
			case -1002 || -1003 || -1004:
				uni.router.route('/pages/follow/follow')
				break;
		}
	},
	authorization(path : string) {
		let redirect_uri = encodeURIComponent(`${store.state.website}${path}`),
			appid = "wx44b35d013a63718d";
		let wx_url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
		window.location.replace(wx_url);
	},
	resetWebUrl(path : string) {
		history.replaceState(null, '', `${store.state.website}${path}`);
	},
	showModel() {
		uni.showModal({
			title: '提示',
			content: '本次操作需要您进行登录验证',
			success: (res) => {
				if (res.confirm) {
					uni.router.route('/pages_login/login_entry/loginEntry')
				}
			}
		});
	}
}





export default global

export type {
	IWithdrawalTypeList,
	IWithdrawalType,
	IPayOption,
	IDeliverOption,
	IUserLevelTypeList,
	IUserLevelType,
	IAgreemenType
}